faApp.controller('statisticsRegisterCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsFaRegisterByMonth().then(function (json) {
        if (!json.statusCode) {
            var xdata = [];
            var ydata = [];
            var data = [];
            angular.forEach(json.list, function (o, i) {
                xdata.push(o.dmonth);
                ydata.push(o.num);
                data.push(o.num);
            });

            $scope.option = {
                title: {
                    text: '每月注册量'
                },
                tooltip: {},
                legend: {
                    data: ['人数']
                },
                xAxis: {
                    axisTick: {
                        alignWithLabel: true
                    },
                    data: xdata
                },
                yAxis: {},
                series: [{
                    name: '人数',
                    type: 'bar',
                    data: ydata
                }]
            };
        }
    });
}]);

faApp.controller('statisticsRegisterRoleCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsFaUserRoleCount().then(function (json) {
        if (!json.statusCode && json.list) {
            var data = [];
            var d = json.list[0];
            data.push({value: d.weitijiao, name: '未提交审核'});
            data.push({value: d.shenhezhong, name: '审核中'});
            data.push({value: d.shibai, name: '审核失败'});
            data.push({value: d.tongguo, name: '审核通过'});


            $scope.option = {
                title: {
                    text: '审核状态统计',
                    // subtext: '',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['未提交审核', '审核中', '审核失败', '审核通过']
                },
                series: [
                    {
                        name: '状态',
                        type: 'pie',
                        radius: '75%',
                        center: ['40%', '60%'],
                        data: data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
        }
    });
}]);

faApp.controller('statisticsOrderCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsOrderByMonth().then(function (json) {
        if (!json.statusCode) {
            var xdata = [];
            var ydata1 = [];
            var ydata2 = [];

            angular.forEach(json.list, function (o, i) {
                xdata.push(o.saleMonth);
                ydata1.push(o.oAmount);
                ydata2.push(o.orderCount);
            });

            $scope.option = {
                title: {
                    text: '订单数据',
                },
                tooltip: {
                    trigger: 'axis',
                    formatter: function (p) {
                        return '成交量:' + p[0].name + ' <br> 成交金额:' + $filter("moneyRender")(p[0].value);
                    }
                },
                legend: {
                    selectedMode: false,
                    data: ['成交量', '成交金额']
                },
                xAxis: [
                    {
                        type: 'category',
                        boundaryGap: true,
                        data: xdata
                    },
                    {
                        type: 'category',
                        boundaryGap: true,
                        data: ydata2
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        scale: true,
                        name: '成交量'
                    },
                    {
                        type: 'value',
                        scale: true,
                        name: '金额',
                        axisLabel: {
                            formatter: function (v, i) {
                                return $filter("moneyRender")(v);
                            }
                        }
                    }
                ],
                series: [
                    {
                        name: '成交金额',
                        type: 'bar',
                        xAxisIndex: 1,
                        yAxisIndex: 1,
                        data: ydata1
                    },
                    {
                        name: '成交量',
                        type: 'line',
                        data: ydata2
                    }
                ]
            };
        }
    });
}]);

faApp.controller('statisticsOrderUserPerCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsOrderUserPer().then(function (json) {
        if (!json.statusCode && json.dto) {
            var data = [];
            var d = json.dto;
            data.push({value: (d.allUserCount - d.noHasOrderUserCount), name: '认证下单人数'});
            data.push({value: d.noHasOrderUserCount, name: '认证未下单人数'});

            $scope.option = {
                title: {
                    text: '审核状态统计',
                    // subtext: '',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['认证下单人数', '认证未下单人数']
                },
                series: [
                    {
                        name: '状态',
                        type: 'pie',
                        radius: '75%',
                        center: ['40%', '60%'],
                        data: data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
        }
    });
}]);

faApp.controller('statisticsOrderFauserRolePrpportionCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsOrderFauserRolePrpportion().then(function (json) {
        if (!json.statusCode && json.list) {
            var data = [];
            var legendData = [];
            var d = json.list;

            angular.forEach(json.list, function (o, i) {
                var s = $filter("faRoleStatusRender")('01', o.uRole);
                data.push({value: o.roleCount, name: s});
                legendData.push(s);
            });

            $scope.option = {
                title: {
                    text: '订单-理财师角色比例',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: legendData
                },
                series: [
                    {
                        name: '状态',
                        type: 'pie',
                        radius: '75%',
                        center: ['50%', '50%'],
                        data: data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
        }
    });
}]);

faApp.controller('statisticsOrderFauserPrpportionCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsOrderFauserPrpportion().then(function (json) {
        if (!json.statusCode && json.list) {
            var data = [];
            var legendData = [];
            var d = json.list;

            angular.forEach(json.list, function (o, i) {
                var s = $filter("faRoleStatusRender")('01', o.uRole);
                data.push({value: o.roleCount, name: s});
                legendData.push(s);
            });

            $scope.option = {
                title: {
                    text: '认证理财师角色比例',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: legendData
                },
                series: [
                    {
                        name: '状态',
                        type: 'pie',
                        radius: '75%',
                        center: ['50%', '50%'],
                        data: data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
        }
    });
}]);

faApp.controller('statisticsOrderRankingCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsOrderUserTotal({pageSize: 10, pageNo: 1}).then(function (json) {
        if (!json.statusCode && json.list) {
            var datay = [];
            var datax = [];
            var dataid = [];
            var tt = '';

            angular.forEach(json.list.reverse(), function (o, i) {
                tt = o.faId + ',,,' + (o.uRealName || '');

                datay.push(tt);
                datax.push(o.oAmount);
            });

            $scope.option = {
                title: {
                    text: '用户订单排行',
                    subtext: 'SFA排名前十的理财师'
                },
                tooltip: {
                    trigger: 'axis',
                    formatter: function (p) {
                        return '成交金额<br>' + $filter("moneyRender")(p[0].value);
                    }
                },

                legend: {
                    data: ['订单总额']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    boundaryGap: [0, 0.01]
                },
                yAxis: {
                    type: 'category',
                    data: datay,
                    axisLabel: {
                        formatter: function (v, i) {
                            return v.split(',,,')[1];
                        }
                    }
                },
                series: [
                    {
                        name: '订单总额',
                        type: 'bar',
                        data: datax
                    }
                ]
            };
        }
    });
}]);

faApp.controller('statisticsCompanyTotalCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    statisticsService.statisticsCompanyTotal({pageSize: 10, pageNo: 1}).then(function (json) {
        if (!json.statusCode && json.list) {
            var datay = [];
            var datax = [];

            angular.forEach(json.list.reverse(), function (o, i) {
                datay.push(o.cName);
                datax.push(o.productCount);
            });

            $scope.option = {
                title: {
                    text: '供应方排行'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {
                    data: ['产品数量']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    boundaryGap: [0, 0.01]
                },
                yAxis: {
                    type: 'category',
                    data: datay,
                    axisLabel: {
                        formatter: function (v, i) {
                            return v.substr(0, 15);
                        }
                    }
                },
                series: [
                    {
                        name: '产品数量',
                        type: 'bar',
                        data: datax
                    }
                ]
            };
        }
    });
}]);

faApp.controller('productKeyWordTotalCtrl', ['$scope', '$location', '$controller', '$route', '$routeParams', '$filter', 'statisticsService', function ($scope, $location, $controller, $route, $routeParams, $filter, statisticsService) {
    $controller('BaseCtrl', {$scope: $scope});

    var feedbackStatus = new Object();
    $scope.feedbackStatus = feedbackStatus;


    var value = {};

    var searchKeyWord = new Object();
    $scope.searchKeyWord = searchKeyWord;
    $scope.config = {
        "pageSize" : 20,
        "pageNo" : 1,
        "feedbackStatus":value,
        "jjbm" : $routeParams.jjbm || ""
    };
    var initData = function (data) {
        console.log(data);
        statisticsService.statisticsProductKeyWord(data).then(function (json) {
            searchKeyWord.data = json.list;
            searchKeyWord.pager = json.pager;
            // searchKeyWord.pager.totalCount = json.count;
        });
    }
    initData($scope.config);

    $scope.pageChanged = function(){
        $scope.config = {
            "pageSize" : 20,
            "pageNo" : 1,
            "feedbackStatus":value,
            "jjbm" : $routeParams.jjbm || ""
        };
        $scope.config.pageNo = searchKeyWord.pager.pageNo;
        initData($scope.config);
    };

    $scope.query = function (data) {
        value = data;
        $scope.config = {
            "pageSize" : 20,
            "pageNo" : 1,
            "feedbackStatus":value,
            "jjbm" : $routeParams.jjbm || ""
        };
        initData($scope.config);
    }

    //未反馈关键词发送消息
    $scope.sendMsg = function (data) {
        if(confirm('无法找到并创建此关键字产品时使用此功能，确认回复？')) {
            var xcxNews = {};
            xcxNews.keyWord = data.keyword;
            xcxNews.content = "此产品没有哇！！！！！！！！！！";
            xcxNews.proUrl = "";
            xcxNews.content = "尊敬的用户，您搜索的产品关键字'"+data.keyword+"'查无此产品!";
            statisticsService.statisticsSendMsg(xcxNews).then(function (json) {
                console.log(json)
                alert('回复成功！')
                $route.reload();
            })
        }
    }

    $scope.showXcxUser = function (item, list) {
        var isshow = item.checked;
        for(var i=0; i<list.length; i++) {
            var d = list[i];
            d.checked = false;
        }
        item.checked = !isshow;

        statisticsService.statisticsProductKeyWordUser({keyword: item.keyword, searchType: item.searchType, feedbackStatus:item.feedbackStatus}).then(function (json) {
            $scope.searchUserList = json.list
        })
    }
}]);